home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / biz / ccard11 / main.c < prev    next >
C/C++ Source or Header  |  1995-01-28  |  2KB  |  117 lines

  1. /*
  2.  *    ccard - credit card number validation
  3.  *    1994 Peter Miller
  4.  *    Public Domain
  5.  *
  6.  *    This program is distributed in the hope that it will be useful,
  7.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9.  *
  10.  * MANIFEST: program entry point
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <ac/stdlib.h>
  15. #include <ac/string.h>
  16.  
  17. #include <ccard.h>
  18. #include <patchlevel.h>
  19.  
  20. static char    *progname;
  21.  
  22.  
  23. static int suffix _((char *, char *));
  24.  
  25. static int
  26. suffix(s1 , s2)
  27.     char    *s1;
  28.     char    *s2;
  29. {
  30.     int len1 = strlen(s1);
  31.     int len2 = strlen(s2);
  32.     return (len2 < len1 && !memcmp(s1 + len1 - len2, s2, len2));
  33. }
  34.  
  35.  
  36. static void print_version _((char *));
  37.  
  38. static void
  39. print_version(s)
  40.     char        *s;
  41. {
  42.     char        *ep;
  43.  
  44.     for (;;)
  45.     {
  46.         ep = strrchr(s, '/');
  47.         if (!ep)
  48.             break;
  49.         if (ep > s && !ep[1])
  50.         {
  51.             *ep = 0;
  52.             continue;
  53.         }
  54.         s = ep + 1;
  55.         break;
  56.     }
  57.     progname = s;
  58.  
  59.     fprintf(stderr, "%s version %s\n", progname, PATCHLEVEL);
  60. }
  61.  
  62.  
  63. int
  64. main(argc, argv)
  65.     int        argc;
  66.     char        **argv;
  67. {
  68.     int        j;
  69.  
  70.     print_version(argv[0]);
  71.     for (j = 1; j < argc; ++j)
  72.     {
  73.         ccard_type_ty    type;
  74.         ccard_error_ty    err;
  75.         char        *s;
  76.  
  77.         err = ccard_valid(argv[j], &type);
  78.         if (err)
  79.         {
  80.             if (type != ccard_type_unknown)
  81.             {
  82.                 fprintf
  83.                 (
  84.                     stderr,
  85.                     "%s: %s: %s (%s)\n",
  86.                     progname,
  87.                     argv[j],
  88.                     ccard_error_name(err),
  89.                     ccard_type_name(type)
  90.                 );
  91.             }
  92.             else
  93.             {
  94.                 fprintf
  95.                 (
  96.                     stderr,
  97.                     "%s: %s: %s\n",
  98.                     progname,
  99.                     argv[j],
  100.                     ccard_error_name(err)
  101.                 );
  102.             }
  103.             exit(1);
  104.         }
  105.         printf("\"%s\" is a", argv[j]);
  106.         s = ccard_type_name(type);
  107.         if (strchr("AEIOUaeiou", s[0]))
  108.             printf("n");
  109.         printf(" %s", s);
  110.         if (!suffix(s, "card"))
  111.             printf(" card");
  112.         printf("\n");
  113.     }
  114.     exit(0);
  115.     return 0;
  116. }
  117.